package modelo.bd.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import modelo.bd.exception.DAOException;
import modelo.dominio.Historico;

public class HistoricoDAO extends AbstractDAO<Historico> {

    @Override
    public void add(Historico entity) throws DAOException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void deleteWhere(String condition) throws DAOException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void update(Historico entity) throws DAOException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    protected ArrayList<Historico> select() throws DAOException {
        try {
            ResultSet resultado = con.ejecutarConsulta(getQuery());
            ArrayList<Historico> historicos = new ArrayList();
            while (resultado.next()) {
                Historico hist = new Historico();
                hist.setIdHistorico(Integer.parseInt(resultado.getString("ID_HISTORICO")));
                hist.setUsuarioCrea(resultado.getString("USUARIO_CREA"));
                hist.setFechaCrea(resultado.getDate("FECHA_CREA"));
                hist.setUsuarioMod(resultado.getString("USUARIO_MOD"));
                hist.setFechaMod(resultado.getDate("FECHA_MOD"));
                hist.setEstado(resultado.getString("ESTADO"));
                historicos.add(hist);
            }
            return historicos;
        } catch (SQLException ex) {
            throw new DAOException("Error en DAO Historico " + ex.getMessage());
        }
    }

    @Override
    public ArrayList<Historico> selectAll() throws DAOException {
        this.setQuery("SELECT * FROM SSMA_HISTORICO_T");
        return select();
    }

    @Override
    public ArrayList<Historico> selectWhere(String condition) throws DAOException {
        this.setQuery("SELECT * FROM SSMA_HISTORICO_T WHERE " + condition);
        return select();
    }
}
